package com.aceslideshows.common.dao.model;

import java.util.Comparator;

/**
 * An entity represents a single record within a database. The id is the
 * surrogate key colulmn of the table.
 * 
 */
public interface SystemEntity // extends Serializable
{

    public static final long NO_ID = 0L;

    /**
     * Comparator used for sorting entities by their Ids.
     */
    public static final Comparator SORT_ASC_ID = new Comparator()
    {

        public int compare(SystemEntity left, SystemEntity right)
        {
            return (int) (left.getId() - right.getId());
        }

        public int compare(Object left, Object right)
        {
            int result = (left instanceof SystemEntity && right instanceof SystemEntity) ? compare(
                    (SystemEntity) left, (SystemEntity) right)
                    : 0;
            return result;
        }
    };

    /**
     * Comparator used for sorting entities by their Ids.
     */
    public static final Comparator SORT_DESC_ID = new Comparator()
    {

        public int compare(SystemEntity left, SystemEntity right)
        {
            return (int) (right.getId() - left.getId());
        }

        public int compare(Object left, Object right)
        {
            int result = (left instanceof SystemEntity && right instanceof SystemEntity) ? compare(
                    (SystemEntity) left, (SystemEntity) right)
                    : 0;
            return result;
        }
    };

    /**
     * Gets the Entity's unique identifier within the system.
     * 
     * @return
     */
    long getId();

    /**
     * Sets the Entity's unique identifier within the system.
     * 
     * @param id
     */
    void setId(long id);

}
